package com.fz.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fz.entity.Role;
import com.fz.service.RoleService;
import com.fz.vo.ResultVo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 存储系统角色信息 前端控制器
 * </p>
 *
 * @author hyr
 * @since 2025-06-18
 */
@RestController
@RequestMapping("/tRole")
public class RoleController {
    @Resource
    RoleService roleService;
    @GetMapping("/list")
    ResultVo<Page<com.fz.entity.Role>> list(Integer PageNo, Integer PageSize)throws InterruptedException {

        return ResultVo.success(roleService.page(new Page<>(PageNo,PageSize)));
    }
    @PostMapping("/add")
    ResultVo<Boolean> addRole(String name,String description,String permission) {
        return ResultVo.success(roleService.add(name,description,permission),"添加角色成功");
    }
    @GetMapping("/getById")
    ResultVo<Role> getById(long id){
        return ResultVo.success(roleService.getById(id));
    }
    @PostMapping("/update")
    ResultVo<Boolean> updateRole(long id, String name,String description,String permission) {
        return ResultVo.success(roleService.update(id,name,description,permission),"修改成功");
    }
    @PostMapping("/del")
    ResultVo<Boolean> deleteRole(Long id,Boolean status) {
        return ResultVo.success(roleService.del(id,status),status ? "启用角色成功" : "禁用角色成功");
    }
}
